import time;
# 导包 线程池
from multiprocessing.dummy import Pool;


def get_text(index):
    # print("开始执行 => %d" % index);
    time.sleep(1);
    # print("结束执行 => %d" % index);


if __name__ == '__main__':
    start_time = time.time();
    for index in range(5):
        get_text(index);
    end_time = time.time();

    print("单线程运行结束，耗时 %d 秒" % (end_time - start_time));

    # 创建线程池
    pool = Pool(5)
    start_time = time.time();
    # 参数1 要执行的阻塞函数，参数2 数据相当于执行阻塞函数得次数
    pool.map(get_text,range(5));
    end_time = time.time();
    print("多线程运行结束，耗时 %d 秒" % (end_time - start_time));
